﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonsLib.Utility;
using System.Data.SqlClient;
using MaxLeaf.Platform.Functions;
using System.Data.Common;
using MaxLeaf.Platform.Commons;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;

namespace MaxLeaf.Platform.DALImplementation
{
    public class imOthersOutputDtlDAL : BaseDAL
    {
         
         

        public void SetStoresOutputDtlId(DBAccess dbcon, int intKey, int intStoresOutputHdrID, int intStoresOutputDtlID)
        {
            string strSql = "update imOthersOutputDtl set StoresOutputHdrId=@StoresOutputHdrId,StoresOutputDtlId=@StoresOutputDtlId where DtlID=@FInterID  ";
            dbcon.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("@FInterID", intKey.ToString())
                ,new SqlParameter("@StoresOutputHdrId", intStoresOutputHdrID.ToString())
                ,new SqlParameter("@StoresOutputDtlId", intStoresOutputDtlID.ToString())
            });
        }

        public void SetPosted(DBAccess dbcon, int intKey)
        {
            string strSql = @"update imOthersOutputDtl set  posted=1  where DtlID=@FInterID and posted=0";
            dbcon.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("@FInterID", intKey.ToString())
 
            });
        }

        public List<int> GetUnpostKeys(DBAccess dbcon, int intHdrID)
        {
            List<int> lst = new List<int>();
            string strSql = "select DtlID from imOthersOutputDtl where HdrID=@HdrID and posted=0 and is_delete=0 ";
            using (DbDataReader rdr = dbcon.GetDataReader(strSql, new SqlParameter[] { new SqlParameter("@HdrID", intHdrID.ToString())
            }))
            {
                while (rdr.Read())
                {
                    lst.Add(rdr.GetInt32(0));
                }

            }

            return lst;
        }

        public void GetRecvData(DBAccess dbcon, int intKey, out int intStoresOutputHdrId, out int intStoresOutputDtlId, out double dblRecvQty)
        {
            intStoresOutputHdrId = 0;
            intStoresOutputDtlId = 0;
            dblRecvQty = 0;
            string strSql = "select StoresOutputHdrId,StoresOutputDtlId,ReqQty from imOthersOutputDtl where DtlID=@DtlID ";
            using (DbDataReader rdr = dbcon.GetDataReader(strSql, new SqlParameter[] { new SqlParameter("@DtlID", intKey.ToString())
            }))
            {
                if (rdr.Read())
                {
                    intStoresOutputHdrId = rdr.GetInt32(0);
                    intStoresOutputDtlId = rdr.GetInt32(1);
                    dblRecvQty = CvtFunc.ToDouble(rdr[2]);
                }

            }
        }

        public void SetUnRecv(DBAccess dbcon, int intKey)
        {
            string strSql = @"update imOthersOutputDtl set  is_delete=1  where DtlID=@FInterID and posted=0";
            dbcon.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("@FInterID", intKey.ToString())
 
            });
        }
    }
}
